#ifndef LEVELBROWSER_H
#define LEVELBROWSER_H

#include <QtGui>
#include "commons.h"

class LevelBrowser : public QObject, public QGraphicsItem
{
    Q_OBJECT
    Q_INTERFACES(QGraphicsItem)
public:
    enum BrowseType {
        PLAY,
        LOAD,
        DEFAULT
    };

    explicit LevelBrowser(QGraphicsItem *parent = 0, QGraphicsScene *scene = 0);
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    QRectF boundingRect() const;

    void setDisplayLevels(const QLinkedList<Level*>& levels);
    void clear();
    void setBrowseType(BrowseType type){this->type = type;}

signals:
    void returnClicked();
    void levelSelected(int id);

public slots:
    void clicked(ButtonItem *who);
    void levelSelected(LevelItem *who);

private:
    ImageItem *background;
    ButtonItem *returnBg;
    ButtonItem *prevButton;
    ButtonItem *nextButton;
    qint32 currentPage;
    QHash<int, QPoint> positionMap;
    BrowseType type;

    QLinkedList<Level*> displayLevels;
    QLinkedList<LevelItem *> displayLevelBgs;



    void initScene();
    void initEventSystem();
    void prevPage();
    void nextPage();
    void updatePage();
};

#endif // LEVELBROWSER_H
